package com.nf.health.app.mine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;

/**
 * 修改个人信息区域
 * @author lgs
 *
 */
public class ModifyUserNameActivity extends BaseActivity implements OnClickListener{
	TextView rightTV;
	EditText et_username;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
		setTitleBar(R.layout.titlebar_base);
		setContent(R.layout.activity_modifyusername);
		TextView titleTV = (TextView) findViewById(R.id.titlebar_title_tv);
		titleTV.setText("修改昵称");
		rightTV = (TextView) findViewById(R.id.titlebar_right_tv);
		rightTV.setText("保存");
		rightTV.setVisibility(View.VISIBLE);
		et_username = (EditText) findViewById(R.id.et_username);
		
		fillView();
		initListener();
	}
	private void fillView() {
		String userName = getIntent().getStringExtra("userName");
		if(userName != null){
			et_username.setText(userName);
		}
		
	}

	private void initListener() {
		findViewById(R.id.titlebar_back_view).setOnClickListener(this);
		rightTV.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.titlebar_back_view:
			finish();
			break;
		case R.id.titlebar_right_tv:
			if(et_username.getText().toString().length() == 0){
				showToast("请输入昵称");
				return ;
			}
			Intent intent = new Intent();
			intent.putExtra("userName", et_username.getText().toString());
			setResult(RESULT_OK, intent);
			finish();
			break;
		default:
			break;
		}
	}
	
	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		super.onActivityResult(arg0, arg1, arg2);
		if(arg0 == 1 && arg1 == RESULT_OK && arg2 != null){
			
		}
	}

}
